#include<iostream>
#include<algorithm>
using namespace std;
typedef struct {
	int p;
	int sum;
}data;
bool cmp(data a,data b){
	if(a.p>b.p)
		return false;
	return true;
}
int main(){
	int  n,m;
	data d[5001];
	cin>>n>>m;
	int a,b;
	for(int i=0;i<m;i++){
		cin>>a>>b;
		d[i].p=a;
		d[i].sum=b;
	}
	sort(d,d+m,cmp);
	int index=0,ans=0;
	while(n>0){
		if(d[index].sum<=n){
			ans+=d[index].p*d[index].sum;
			n-=d[index].sum;
				index++;
		}
		else{
			ans+=d[index].p*n;
			n=0;
		}
	}
	cout<<ans;
}
